#include "xmlrpcclient.h"
#include "xmlrpcconv.h"

XmlRpcClient::XmlRpcClient( const QString &host, const quint16 port )
                : HttpClient( host, port, "/interface/xmlrpc", HttpClient::POST )
{
	connect( this, SIGNAL( dataReady( QByteArray ) ), SLOT(onDataReady( QByteArray ) ) );

}


void XmlRpcClient::execute( const QString &method, const QVariantList &params )
{
	//	qDebug() << "XmlRpcClient::execute " << method;
        setPostData( toXmlRpcRequest( method, params ) );

        deferredStart();
				//qDebug() << "XmlRpcClient::wait...";
}

void XmlRpcClient::onDataReady( const QByteArray &data )
{
        QString err;

				//qDebug() << "XmlRpcClient::onDataReady" ;
        QVariant response = fromXmlRpcResponse( data, err );
        // TODO fault
        emit dataReady( response );
}

